//
//  XWSetView.swift
//  XWSurSpeed
//
//  Created by hopemobi-1 on 2024/8/7.
//

import UIKit

class XWSetView: UIView {
    private var container:UIView!
    override init(frame: CGRect) {
        super.init(frame: frame)
        showUI()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    @IBAction func XWPrivacyButtonClick(_ sender: UIButton) {
        let vc = XWPrivacyPolicyViewController()
        PresentViewController(vc)
    }
    @IBAction func XWAboutButtonClick(_ sender: UIButton) {
        let vc = XWAboutUsViewController()
        PresentViewController(vc)
    }
    
    @IBAction func XWClearButtonClick(_ sender: UIButton) {
        let clearView = XWClearCacheView(frame: .zero)
        currentViewController().view.addSubview(clearView)
        clearView.snp.makeConstraints { make in
            make.top.equalTo(currentViewController().view)
            make.left.equalTo(currentViewController().view)
            make.bottom.equalTo(currentViewController().view)
            make.right.equalTo(currentViewController().view)
        }
        self.removeFromSuperview()
    }
    
    @IBAction func XWShareBUttonClick(_ sender: UIButton) {
        let title = getAppName()
        let imageToShare = UIImage(named: "basics_logo")
        let activityItems = [title,imageToShare!] as [Any]
        let activityVC = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
        activityVC.excludedActivityTypes = [.print,.saveToCameraRoll,.assignToContact,.saveToCameraRoll]
        currentViewController().present(activityVC, animated: true, completion: nil)
    }
    
    @IBAction func XWRemoveTapClick(_ sender: UITapGestureRecognizer) {
        self.removeFromSuperview()
    }
    
}
extension XWSetView {
    private func showUI() {
        container = Bundle.main.loadNibNamed("XWSetView", owner: self,options: nil)?.first as? UIView
        container.frame = bounds
        addSubview(container)
    }
}
